package com.app.megaprosoft.modyimcarcare;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import com.megaprosoft.modyimcarcare.R;



import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class CheckCarByPnlActivity extends Activity {
	Button bth,btnB,btc,btCancel;
	TextView RegID,time;
	RadioButton chx1,chx2;
	connect con = new connect(); 
	ResultSet rs;
	//private boolean input=false;
	ArrayList<String> Status = new ArrayList<String>();	
	public static String DTIDS,ID;
	String StatuS,ServiceID,pass,RegisID,id,Time,Type,NameUser,Normal1="",NameInput,company;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_check_car_by_pnl);
		
		NameInput = getIntent().getExtras().getString("name");
		company = getIntent().getExtras().getString("CompanyS");
		
        
			RegID = (TextView) findViewById(R.id.ShowRegID);		
			
			bth = (Button) findViewById(R.id.button1);
			btc = (Button) findViewById(R.id.buttonCheck);
			btCancel =  (Button) findViewById(R.id.button2);
			
			chx1 = (RadioButton) findViewById(R.id.C1);		
			chx2 = (RadioButton) findViewById(R.id.C2);	
			
			
			id = getIntent().getExtras().getString("IntentID");		
			RegisID = getIntent().getExtras().getString("RegisID");	
			Type = getIntent().getExtras().getString("Type");
			NameUser = getIntent().getExtras().getString("nameCheck");
					
			RegID.setText(RegisID); 
	
					Status();
	///////////////////////////time /////////////////////////////				
					Calendar c = Calendar.getInstance();
					SimpleDateFormat df = new SimpleDateFormat("HH:mm dd-MM-yyyy");
					String formattedDate = df.format(c.getTime());

			        // txtResult
			        time = (TextView) findViewById(R.id.TimeviewList);
			        time.setText(formattedDate);
			        Time = time.getText().toString();
			        
			        
					///////////////////////////////////////////////////1		
			        chx1.setOnClickListener(new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
					// TODO Auto-generated method stub
						chx1.isChecked();
					Normal1 ="���º����";
					}
					});
					
					
					///////////////////////////////////////////////////////2		
			        chx2.setOnClickListener(new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
					// TODO Auto-generated method stub
						chx2.isChecked();
					Normal1 ="������º����";
					}
					});
			        
			        
			        
			        
			        
			        
			        
			
					
					
					
////////////////////////////////Button	ok///////////////////////////	
				bth.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
				

					String sql = "UPDATE ServiceDetail_old SET Status = '"+StatuS+"',LastUpdate='"+Time+
							"' WHERE ServiceID = '"+id+"' " 	;
				
				
				
				if(con.editData(sql)){	 
				Toast.makeText(CheckCarByPnlActivity.this, "����¹�ŧʶҹ�����", Toast.LENGTH_SHORT).show();
				Intent newActivityAdd = new Intent(CheckCarByPnlActivity.this,Detail.class);
				newActivityAdd.putExtra("name", NameInput);
				newActivityAdd.putExtra("CompanyS", company);
				startActivity(newActivityAdd);
				
				
				
				}else{
				Toast.makeText(CheckCarByPnlActivity.this, "ʶҹ��ѧ�������¹�ŧ", Toast.LENGTH_SHORT).show();
				}
				
				
				
				String sqlInsert = "INSERT INTO CheckByPersonnel " +
						"(ServiceID,ServiceType,RegisterID,namePersonnel,CheckCar,Status,timeCheck) " +
						"VALUES (" +
						"'"+id+"'" + ',' + 
						"'"+Type+"'" + ',' + 
						"'"+RegisID+"'" + ',' + 
						"'"+NameUser+"'" + ',' +
						"'"+Normal1+"'" + ',' +
						"'"+StatuS+"'" + ',' +
						"'"+Time+"'" + ") ";
				
				if(con.addData(sqlInsert)){	 
					Toast.makeText(CheckCarByPnlActivity.this, "����¹�ŧʶҹ�����", Toast.LENGTH_SHORT).show();
					
					finish();
					
					}else{
					Toast.makeText(CheckCarByPnlActivity.this, "ʶҹ��ѧ�������¹�ŧ", Toast.LENGTH_SHORT).show();
					
					}
				}
				});
////////////////////////////////Button	check///////////////////////////	+
				
				btc.setOnClickListener(new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent goCheck = new Intent (CheckCarByPnlActivity.this,ChkSafStdMainActivity.class);
						goCheck.putExtra("IntentID", id); 	
						goCheck.putExtra("RegisID", RegisID); 
						goCheck.putExtra("Type", Type); 
						goCheck.putExtra("nameCheck", NameUser);
						startActivity(goCheck);
						
					}
				});
				
				
////////////////////////////////Button	cancel///////////////////////////	
				btCancel.setOnClickListener(new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent newActivityAdd = new Intent(CheckCarByPnlActivity.this,Detail.class);
						newActivityAdd.putExtra("name", NameInput);
						newActivityAdd.putExtra("CompanyS", company);
						startActivity(newActivityAdd);
						
						finish();
						
						
					}
				});
	}

	
	///////////////////////////////////////// Status  ////////////////////////////
	
	private void Status() {
		
		String tusTmp = getIntent().getExtras().getString("Status");
		
		final Spinner spn = (Spinner) findViewById(R.id.dropstatus);

		
		Status.add(tusTmp);
		Status.add("��ҧ��");
		Status.add("����������");
		Status.add("��Ǩ��");
		Status.add("��Ǩ����");
		Status.add("�ͻ����");
		
		
		
	ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Status);
	empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
	spn.setAdapter(empolyeeAdapter);

	spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 

	public void onItemSelected(AdapterView<?> adapterView, 
		View view, int i, long l) { 
		// TODO Auto-generated method stub
		
		
		StatuS = Status.get(i);
		
		}
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		Toast.makeText(CheckCarByPnlActivity.this,
					String.valueOf("ʶҹ��ա������¹�ŧ����"),
						Toast.LENGTH_SHORT).show();
	} 

	});

	}
	
	
	////////////////////////////////////////////////////////////////////
	
		
		@Override
		public void onBackPressed() {
		 
		}

}
